#pragma once

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <Windows.h>
#include <wininet.h>
#include <WinSock2.h>
#include <WS2tcpip.h>

#define USER_AGENT "Gw2Maps"
#define POST "POST"
#define GET "GET"
#define ACCEPT_TYPE_TEXT "text/*"
#define CONNECTION_HTTPS 2
#define CONNECTION_HTTP 1
#define CONNECTION_ERROR 0

class Connection
{
public:
	Connection(void);
	~Connection(void);
	int openConnection(const char *addr);
	int openSockConnection(const char *ip, u_short port);
	void closeSockConnection();
	void closeConnection(){if(connected){InternetCloseHandle(session); InternetCloseHandle(con); InternetCloseHandle(open); connected = false;}}
	char* sendData(const char *data);
	int sockSend(char *data, int size){if(!connected || sock == INVALID_SOCKET)return -1; return send(sock, data, size, 0);}
	int sockRecv(char *buffer, int size){if(!connected || sock == INVALID_SOCKET)return -1; return recv(sock, buffer, size, 0);}

private:
	SOCKET sock;
	HINTERNET open, con, session;
	bool ssl, connected;
	char server[256], directory[256];

	int analyseURL(const char *url);
};

